'''
Description: 
Autor: didiplus
Date: 2023-01-13 15:19:35
LastEditors: lin
LastEditTime: 2023-01-13 15:35:13
'''

import aiohttp
import asyncio
from loguru import logger
from  cnblogs_spider import urls
import time

async def async_craw(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as resp:
            result = await resp.text()
            logger.info("craw url {},{}".format(url,len(result)))


loop = asyncio.get_event_loop()
# 定义超级循环
tasks = [ loop.create_task(async_craw(url))  for url in urls]


start = time.time()
loop.run_until_complete(asyncio.wait(tasks))
end = time.time()
logger.info("use time {}秒".format(end-start))
